package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: OrderController
 *
 * @AUTHOR: zhang
 * DATE: 2023/12/13
 * DESCRIPTION :
 */
@Slf4j
@Api(tags = "C端-订单信息表现层接口") //@Api:用户描述类的相关信息
@RestController
@RequestMapping("/user/order")
public class OrdersController {

    @Resource
    private OrdersService ordersService;


    @ApiOperation("提交订单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("【提交订单】{}",ordersSubmitDTO);
        OrderSubmitVO ordersSubmitVO = ordersService.submitOrder(ordersSubmitDTO);
        return Result.success(ordersSubmitVO);
    }


    @ApiOperation("查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("【查询历史订单】,{}",ordersPageQueryDTO);
        PageResult pageResult = ordersService.getHistoryOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderDetails(@PathVariable Long id){
        log.info("【查询订单详情】订单id:{}",id);
        OrderVO orderVO = ordersService.getOrderDetails(id);
        return Result.success(orderVO);
    }

    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result anotherOrder(@PathVariable Long id){
        log.info("【再来一单】订单id：{}",id);
        ordersService.getOrderAgain(id);
        return Result.success();
    }
}
